package com.help.knowhelps.view;

import java.util.Random;

import com.help.knowhelps.R;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
public class ProgressNotification {
	int notification_id = 0;
	NotificationManager nm;
	Notification notification;
	int progress;
	int mMax = 100;
	boolean mAutoDisappear = true;// disappear after done
	private Context context;
	private boolean mIsRunning;
	
	private int notificationLayoutId;
	
	public boolean isAutoDisappear() {
		return mAutoDisappear;
	}

	public void setAutoDisappear(boolean autoDisappear) {
		mAutoDisappear = autoDisappear;
	}
	
	public void setNotificationId(int id){
		notification_id = id;
	}
	
	public int getNotificationId(){
		return notification_id;
	}
	
	public ProgressNotification(Context activity, int icon,
			CharSequence tickerText, Bitmap bm, String key) {
		this(activity, icon, 100, 0, tickerText, bm, key);
		context = activity;
	}

	public ProgressNotification(Context activity, int icon, int max,
			int progress, CharSequence tickerText, Bitmap bm, String key) {
//		notification_id = new Random().nextInt();// randomize it
//
//		nm = (NotificationManager) activity
//				.getSystemService(Context.NOTIFICATION_SERVICE);
//		notification = new Notification(android.R.drawable.stat_sys_download, tickerText,
//				System.currentTimeMillis());
//		
//		notificationLayoutId = R.layout.nq_notification;
//		
//		PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, notification_id, new Intent(PackRcv.NEW_EVENT_DELETE).putExtra(PackRcv.NOTIFICATION_KEY, key), PendingIntent.FLAG_UPDATE_CURRENT);
//		
//		RemoteViews contentView = new RemoteViews(activity.getPackageName(), notificationLayoutId);
//		contentView.setTextViewText(R.id.nq_notification_title, tickerText);
//		contentView.setImageViewBitmap(R.id.nq_notification_icon, bm);
//		contentView.setProgressBar(R.id.nq_progress, max, 0, true);
//		contentView.setOnClickPendingIntent(R.id.nq_notification_button, pendingIntent);
//		
//		if(Utils.getAndroidSDKVersion() < 11){
//			Intent notificationIntent = new Intent(activity, Activity.class);
//			notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//			PendingIntent contentIntent = PendingIntent.getActivity(activity, 0,
//					notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//	
//			notification.contentIntent = contentIntent;
//		}
//		
//		notification.deleteIntent = pendingIntent;
//		notification.contentView = contentView;
//	}
//	
//	public void setMax(int max) {
//		if (mMax == max || 0 == notificationLayoutId) {
//			return;
//		}
//		if (null != notification.contentView) {
//			if (Utils.printLog) {
//				 Log.d(Utils.KIDSMODE_TAG, "step 2_1");
//			}
//			mMax = max;
//			notification.contentView.setProgressBar(R.id.nq_progress, max, progress,
//					false);
//			if (Utils.printLog) {
//				 Log.d(Utils.KIDSMODE_TAG, "step 2_2");
//			}
//		}
//	}
//	
//	public int progress() {
//		return progress;
//	}
//
//	public void update(int progress) {
//		if (Utils.printLog) {
//			 Log.d(Utils.KIDSMODE_TAG, "step 3_0");
//		}
//		if (progress == this.progress || 0 == notificationLayoutId) {// no change
//			return;
//		}
//		this.progress = progress;
//		
//		if (notification != null && notification.contentView !=null) {
//			if (Utils.printLog) {
//				 Log.d(Utils.KIDSMODE_TAG, "step 3_1 mMax:" + mMax + ";progress:" + progress);
//			}
//			
//			notification.contentView.setProgressBar(R.id.nq_progress, mMax, progress, false);
//			nm.notify(notification_id, notification);
//			if (Utils.printLog) {
//				 Log.d(Utils.KIDSMODE_TAG, "step 3_2");
//			}
//		}
//
//		// now,gone
//		if (mAutoDisappear && progress >= mMax) {
//			if (Utils.printLog) {
//				 Log.d(Utils.KIDSMODE_TAG, "step 3_3");
//			}
//			cancel();
//		}
//	}
//
//	public void cancel() {
//		nm.cancel(notification_id);
//	}
//	
//	public void setDownloadStatus(CharSequence text){
//		if(TextUtils.isEmpty(text) || null == notification.contentView || 0 == notificationLayoutId)
//			return;
//		
//		notification.contentView.setTextViewText(R.id.nq_notification_title, text);
//	}
//	
//	public void setDownloadIcon(Bitmap bitmap){
//		if(null == bitmap || null == notification.contentView || 0 == notificationLayoutId)
//			return;
//		
//		notification.contentView.setImageViewBitmap(R.id.nq_notification_icon, bitmap);
//	}
//	
//	public void setRunningStatue(boolean isRunning){
//		mIsRunning = isRunning;
//	}
//	
//	public boolean isRunningNotification(){
//		return mIsRunning;
	}
}
